package site.wenneng.dev.common.util;

import com.baomidou.mybatisplus.core.conditions.interfaces.Func;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class CollectorUtils {

    public static <T> Collector<T, ?, List<T>> toDistinctList(Function<T, ?> uniqueKeyFunction) {
        return Collectors.collectingAndThen(
                Collectors.toMap(uniqueKeyFunction, Function.identity(), (o1, o2) -> o1),
                item -> new ArrayList<>(item.values())
        );
    }
}
